var special_flag = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？ ]");

$(document).ready(function () {

})

$("#loginname").blur(function () {
    var showWrong = false;
    var wrongMsg;
    if ($(this).val()==null || $(this).val()== "" || $(this).val()== undefined){
        showWrong = true;
        wrongMsg = "账号不能为空！";
    }else if ($(this).val().match(/^[ ]*$/)){
        showWrong = true;
        wrongMsg= "账号不能包含空格！";
    } else if (special_flag.test($(this).val())){
        showWrong = true;
        wrongMsg="账号不能包含特殊符号！";
    } else{
        showWrong = false
    }
    if (showWrong){
        $(this).css("border-color","#FF5722");
        $(".content .error_msg2").css('display','block');
        $(".content .error_msg2").text(wrongMsg);
    }else {
        $(".content .error_msg2").css('display','none');
        $(this).css("border-color","#eee");
    }
})

$("#password").blur(function () {
    var showWrong = false;
    var wrongMsg;
    if ($(this).val()==null || $(this).val()== "" || $(this).val()== undefined){
        showWrong = true;
        wrongMsg = "密码不能为空！";
    }else if ($(this).val().match(/^[ ]*$/)){
        showWrong = true;
        wrongMsg= "密码不能包含空格！";
    } else if (special_flag.test($(this).val())){
        showWrong = true;
        wrongMsg="密码不能包含特殊符号！";
    } else{
        showWrong = false
    }
    if (showWrong){
        $(this).css("border-color","#FF5722");
        $(".content .error_msg2").css('display','block');
        $(".content .error_msg2").text(wrongMsg);
    }else {
        $(".content .error_msg2").css('display','none');
        $(this).css("border-color","#eee");
    }
})



function signin() {
    // var loginid = $("#loginId").val();
    // if (loginid.indexOf("@")>0){
    //     $("#loginId").attr("name","email");
    // }else if (loginid.length==11){
    //     $("#loginId").attr("name","telephone");
    // }
    var loginname=$("#loginname").val();
    var password = $("#password").val();

    var user = {
        loginname:loginname,
        password:password
    }

    if (loginname=="" || password==""){

    }else {
        $.ajax({
        type: "post",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        // url: "/loginLog/login?loginname="+loginname+"&password="+password,
        // data:JSON.stringify($("#login-form")),
        url: "/loginLog/login",
        data:user,
        success: function (result) {
            if (result.code == 200) {

                window.top.location.replace("/bus/toindex");
                // $("#mainIframe",parent.document).attr("src","/toMainContent");
                $("#signWindow",parent.document).css("display","none");
                $("#head-portrait",parent.document).css("display","block");



            }else if (result.code == -1){
                $(".content .error_msg2").css('display','block').show(300).delay(3000).hide(300);
                $(".content .error_msg2").text(result.msg);
            }
            ;
        },
        error : function() {

            ShowMsg("请重试！");

        }
    });
    }
}

function signup() {
        $("#mainIframe",parent.document).attr("src","toSignup");
}
